const productDAO = require('../dao/productDAO')


function findAll(callback) {
    productDAO.select(callback);
}


function findByName(productName,callback) {
    productDAO.selectByName(productName,callback);
}

function add(product,callback) {

    const resMsg = {
        flag :false
    }
    productDAO.insert(product,function (affected) {
        if(affected>0){
            resMsg.flag = true;
        }
        callback(resMsg);
    });
}

function edit(product,callback) {
    const resMsg = {
        flag :false
    }
    productDAO.update(product,(affected)=>{
        if(affected>0){
            resMsg.flag = true;
        }
        callback(resMsg);
    });
}

function remove(productId,callback) {
    const resMsg = {
        flag :false
    }
    productDAO.remove(productId,(affected)=>{
        if(affected>0){
            resMsg.flag = true;
        }
        callback(resMsg);
    })
}

module.exports ={
    findAll,
    findByName,
    add,
    edit,
    remove
}
